package com.unicloud.medical.oss.client.autoconfigure;

import io.github.resilience4j.circuitbreaker.CircuitBreaker;
import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

@Configuration
public class Resilience4jAutoConfiguration {

    @Bean
    public CircuitBreaker circuitBreaker() {
        CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom()
                .failureRateThreshold(50) // 触发熔断的失败率阈值
                .waitDurationInOpenState(Duration.ofSeconds(10)) // 熔断器打开后持续的时间
                .build();
        return CircuitBreaker.of("defaultCircuitBreakerConfig", circuitBreakerConfig);
    }

}
